<template>
  <div class="app-container">
    <ht-table
      ref="dataTable"
      :multi-select="false"
      :showSerialNumber="false"
      :dictMap="dictMap"
      :queryParams="queryParams"
      :tableBindColumns="tableBindColumns"
      :opButtonList="opButtonList"
      :reqConfig="regConfig"
      :randomRowKey="true"
    >
      <template v-slot:operate>
        <el-table-column label="操作" align="left" width="50" fixed="right">
          <template slot-scope="scope">
            <ht-button-group
              :buttonList="[
                {
                  label: '维护',
                  doFunc: () => {
                    handleAction('detail', scope.row);
                  },
                },
              ]"
            />
          </template>
        </el-table-column>
      </template>
    </ht-table>

    <!-- 添加或修改弹出框 -->
    <el-dialog
      :title="title"
      center
      :visible.sync="open"
      v-if="open"
      width="1024px"
      :destroy-on-close="true"
      :append-to-body="true"
      :close-on-click-modal="false"
    >
      <el-form ref="detailForm" :model="detailForm" label-width="130px">
        <el-card class="form-card txnInfo-card" disabled="true">
          <div slot="header" class="label-header-msg">
            <span>业务查询信息</span>
          </div>
          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="查询流水号" prop="oriId">
                <el-input v-model="detailForm.oriId" :disabled="true" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="报文标识号" prop="pkgId">
                <el-input v-model="detailForm.pkgId" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="工作日期" prop="workDate">
                <el-date-picker
                  v-model="detailForm.workDate"
                  style="width: 100%"
                  type="date"
                  value-format="yyyyMMdd"
                  :disabled="true"
                />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="CPG日期" prop="vdate">
                <el-date-picker
                  v-model="detailForm.vdate"
                  style="width: 100%"
                  type="date"
                  value-format="yyyyMMdd"
                  :disabled="true"
                />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="发起参与机构" prop="sender">
                <el-input v-model="detailForm.sender" :disabled="true" />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="发起直接参与机构" prop="directSender">
                <el-input v-model="detailForm.directSender" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="发起参与机构名称" prop="senderName">
                <el-input v-model="detailForm.senderName" :disabled="true" />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="接收参与机构" prop="rcver">
                <el-input v-model="detailForm.rcver" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="接收直接参与机构" prop="directRecver">
                <el-input v-model="detailForm.directRecver" :disabled="true" />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="接收参与机构名称" prop="rcverName">
                <el-input v-model="detailForm.rcverName" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="查询类型" prop="inqType">
                <el-select style="width: 100%" v-model="detailForm.inqType" placeholder="查询类型" :disabled="true">
                  <el-option
                    v-for="dict in dictMap.INQ_TYPE_314_QUERY"
                    :key="dict.value"
                    :label="`${dict.value}-${dict.text}`"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="原发起参与机构" prop="oriSender">
                <el-input v-model="detailForm.oriSender" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="原报文标识号" prop="oriPkgId">
                <el-input v-model="detailForm.oriPkgId" :disabled="true" />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="原报文类型" prop="oriPkgType">
                <el-select
                  style="width: 100%"
                  v-model="
                    detailForm.oriPkgType === null || detailForm.oriPkgType === undefined
                      ? ''
                      : detailForm.oriPkgType + '-' + detailForm.oriPkgTypeDesc
                  "
                  placeholder="原报文类型"
                  :disabled="true"
                ></el-select>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="原明细标识号" prop="oriDtlId">
                <el-input v-model="detailForm.oriDtlId" :disabled="true" />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="原业务类型" prop="oriBizType">
                <el-select
                  style="width: 100%"
                  v-model="
                    detailForm.oriBizType === null || detailForm.oriBizType === undefined
                      ? ''
                      : detailForm.oriBizType + '-' + detailForm.oriBizTypeDesc
                  "
                  placeholder="原业务类型"
                  :disabled="true"
                ></el-select>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="原交易流水/批次号" prop="oriIdTrue">
                <el-input v-model="detailForm.oriIdTrue" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="24">
              <el-form-item label="查询内容" prop="queryContent">
                <el-input v-model="detailForm.queryContent" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>
        </el-card>

        <el-card
          class="form-card txnInfo-card"
          v-if="
            this.detailForm.noteNumber !== '' &&
            this.detailForm.noteNumber !== null &&
            this.detailForm.noteNumber !== undefined
          "
        >
          <div slot="header" class="label-header-msg">
            <span>银行承兑汇票查询信息</span>
          </div>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="票据号码" prop="noteNumber">
                <el-input v-model="detailForm.noteNumber" :disabled="true" />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="承兑日期" prop="acceptDate">
                <el-date-picker
                  v-model="detailForm.acceptDate"
                  style="width: 100%"
                  type="date"
                  value-format="yyyyMMdd"
                  :disabled="true"
                />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="出票日期" prop="issueDate">
                <el-date-picker
                  v-model="detailForm.issueDate"
                  style="width: 100%"
                  type="date"
                  value-format="yyyyMMdd"
                  :disabled="true"
                />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="汇票到期日" prop="draftMaturity">
                <el-date-picker
                  v-model="detailForm.draftMaturity"
                  style="width: 100%"
                  type="date"
                  value-format="yyyyMMdd"
                  :disabled="true"
                />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="出票人全称" prop="issueName">
                <el-input v-model="detailForm.issueName" :disabled="true" />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="收票人全称" prop="payeeName">
                <el-input v-model="detailForm.payeeName" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="付款人全称" prop="payerBankName">
                <el-input v-model="detailForm.payerBankName" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>
        </el-card>

        <el-card
          class="form-card txnInfo-card"
          v-if="
            this.detailForm.noteNumber !== '' &&
            this.detailForm.noteNumber !== null &&
            this.detailForm.noteNumber !== undefined
          "
        >
          <div slot="header" class="label-header-msg">
            <span>业务查复内容</span>
          </div>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item
                label="查复内容"
                prop="reviewContent"
                :rules="{ required: true, message: '请输入查复内容：', trigger: 'blur' }"
              >
                <el-select style="width: 100%" v-model="detailForm.reviewContent" placeholder="查复内容" clearable>
                  <el-option
                    v-for="dict in dictMap.REVIEW_CONTENT"
                    :key="dict.value"
                    :label="`${dict.value}-${dict.text}`"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item
                label="不符项为"
                prop="rspContent"
                :rules="{ required: true, message: '请选择不符项：', trigger: 'blur' }"
                v-if="this.detailForm.reviewContent === '1'"
              >
                <el-select
                  style="width: 100%"
                  v-model="detailForm.rspContent"
                  placeholder="不符项为"
                  clearable
                  multiple
                >
                  <el-option
                    v-for="dict in options"
                    :key="dict.value"
                    :label="`${dict.label}`"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
        </el-card>

        <el-card
          class="form-card txnInfo-card"
          v-if="
            this.detailForm.noteNumber === '' ||
            this.detailForm.noteNumber === null ||
            this.detailForm.noteNumber === undefined
          "
        >
          <div slot="header" class="label-header-msg">
            <span>业务查复内容</span>
          </div>

          <el-row type="flex">
            <el-col :span="24">
              <el-form-item
                label="查复内容："
                prop="rspContentOther"
                :rules="{ required: true, message: '请输入查复内容：', trigger: 'blur' }"
              >
                <el-input v-model="detailForm.rspContentOther" type="textarea" maxlength="256" show-word-limit/>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="24">
              <el-form-item label="备注" prop="reviewRemarks">
                <el-input v-model="detailForm.reviewRemarks" type="textarea" maxlength="256" show-word-limit/>
              </el-form-item>
            </el-col>
          </el-row>
        </el-card>
      </el-form>
      <div slot="footer" class="dialog-footer" align="center">
        <el-button type="primary" @click="submitForm" v-loading.fullscreen.lock="loading">提 交</el-button>
        <el-button @click="refresh">重 置</el-button>
        <el-button @click="printDetail">打 印</el-button>
        <el-button @click="cancel">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { apiUrlConfigQuery, inquiryResponseEntryDetail, inquiryResponseEntrySave } from "@/api/cnaps/ccms/315";
import { listPageMixin } from "@/libs/listPageMixin";
import { amountThousandsFormatter } from "@/utils/table_col_formatter";
export default {
  name: "InquiryResponseEntry",
  mixins: [listPageMixin],
  components: {},
  data() {
    return {
      defaultEventKey: "bepsEventKey",
      queryParams: {
        reqId: undefined,
      },

      loading: false,

      options: [
        {
          value: "票据号码",
          label: "票据号码",
        },
        {
          value: "承兑日期",
          label: "承兑日期",
        },
        {
          value: "出票日期",
          label: "出票日期",
        },
        {
          value: "汇票到期日",
          label: "汇票到期日",
        },
        {
          value: "交易金额",
          label: "交易金额",
        },
        {
          value: "出票人全称",
          label: "出票人全称",
        },
        {
          value: "收票人全称",
          label: "收票人全称",
        },
        {
          value: "付款行全称",
          label: "付款行全称",
        },
      ],
      // 搜索
      formOptions: [],
      //
      searchFormDictList: ["INQ_TYPE_314_QUERY", "REVIEW_CONTENT"],
      // 列信息
      regConfig: apiUrlConfigQuery,
      tableBindColumns: [
        { prop: "oriId", label: "查询流水号", width: "200" },
        { prop: "vdate", label: "CPG日期", type: "date" },
        { prop: "workDate", label: "工作日期", type: "date" },
        { prop: "inqType", label: "查询类型", dictCode: "INQ_TYPE_314_QUERY" },
        { prop: "sender", label: "发起参与机构", sortable: false, width: "200" },
        { prop: "oriPkgId", label: "原报文标识号", sortable: false, width: "200" },
        { prop: "oriPkgType", label: "原报文类型", sortable: false, width: "200" },
        {
          prop: "oriAmount",
          label: "原金额",
          type: "price",
        },
        { prop: "rcvTime", label: "接收时间", type: "date", width: "200" },
      ],

      // 是否显示弹出层
      open: false,
      // 表单参数
      detailForm: {
        backType: undefined,
        sysCode: undefined,
        // remarks: undefined,
        // backResult:undefined
      },
      totalRecord: 0,
      totalPage: 0,
      needCount: 0,
    };
  },
  mounted() {},
  methods: {
    /***
     * 按钮操作汇总
     */
    /***
     * 按钮操作汇总
     */
    handleAction(type, row = {}) {
      switch (type) {
        case "detail":
          this.handleDetail(row);
          break;
      }
    },

    // 关闭按钮
    cancel() {
      this.open = false;
    },

    /** 详情按钮操作 */
    handleDetail(row) {
      this.title = "业务查复录入维护";
      inquiryResponseEntryDetail(row.oriId).then((response) => {
        this.open = true;
        this.detailForm = response.result;
        this.$set(this.detailForm, "rspContentOther", "");
        this.$set(this.detailForm, "reviewRemarks", "");
      });
    },

    /** 提交按钮 */
    submitForm: function () {
      this.$refs["detailForm"].validate((valid) => {
        if (valid) {
          this.loading = true;
          inquiryResponseEntrySave(this.detailForm)
            .then((response) => {
              this.msgSuccess("录入成功");
              this.refresh();
              this.open = false;
              this.loading = false;
              this.$nextTick(() => {
                this.$refs.dataTable.doQuery(true);
              });
            })
            .catch((err) => {
              this.loading = false;
            });
        }
      });
    },
    //点击重置按钮
    refresh() {
      this.resetForm("detailForm");
    },

    //打印
    printDetail() {
      this.$print(this.$refs["detailForm"]);
    },
  },
};
</script>
